<template>
  <div class="progress-circle">
      <!-- viewBox从(0,0)开始x100，y100 ,version和xmlns不用管 -->
    <svg
      :style="circleStyle"
      viewBox="0 0 100 100"
      version="1.1"
      xmlns="http://www.w3.org/2000/svg"
    >
    <!-- 半径50，圆心坐标50，50 -->
      <!-- <circle
        class="progress-background"
        r="50"
        cx="50"
        cy="50"
        fill="transparent"
      /> -->
      <!-- 单位为百分比 ，stroke-dasharray是一条围绕圆边长度为周长的虚线-->
      <circle
        class="progress-bar"
        r="50"
        cx="50"
        cy="50"
        fill="transparent"
        :stroke-dasharray="dashArray"
        :stroke-dashoffset="dashOffset"
      />
    </svg>
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'progress-circle',
  props: {
    circleStyle: {
      type: Object,
      default: () => { }
    },
    progress: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      dashArray: Math.PI * 100
    }
  },
  computed: {
    dashOffset () {
      return (1 - this.progress) * this.dashArray
    }
  }
}
</script>

<style lang="scss" scoped>
  .progress-circle {
    position: relative;
    circle {
      stroke-width: .341151rem;
      transform-origin: center;
      &.progress-bar {
        //   默认初始位置是圆的最右侧，因此要-90
        transform: scale(0.9) rotate(-90deg);
        stroke: $color-theme;
      }
    }
  }
</style>
